package com.hqyj.repertory.service.impl;
import com.hqyj.product.mapper.ProductInfoMapper;
import com.hqyj.product.model.ProductInfo;
import com.hqyj.purchase.mapper.PurchaseInfoMapper;
import com.hqyj.purchase.model.PurchaseInfo;
import com.hqyj.repertory.mapper.RepertoryMapper;
import com.hqyj.repertory.model.Repertory;
import com.hqyj.repertory.service.RepertoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@Service
public class RepertoryServiceIml implements RepertoryService {
    @Autowired
    RepertoryMapper repertoryMapper;
    @Autowired
    PurchaseInfoMapper purchaseInfoMapper;
    @Autowired
    ProductInfoMapper productInfoMapper;
    @Override
    public ArrayList<Repertory> queryAllRepertory() {
        return repertoryMapper.queryAllRepertory();
    }

    @Override
    public void addRepertory(Repertory repertory) {
        repertoryMapper.insertSelective(repertory);
    }

    @Override
    public Repertory queryRepertoryById(int id) {
        return repertoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateRepertory(Repertory repertory) {
        repertoryMapper.updateByPrimaryKeySelective(repertory);
    }

    @Override
    public void deleteRepertory(int id) {
        repertoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public ArrayList<Repertory> queryRepertoryCondition() {
        return repertoryMapper.queryRepertoryCondition(100);
    }

    @Override
    public Repertory queryRepertoryByProductMaterialsName(String name) {
        return repertoryMapper.queryRepertoryByProductMaterialsName(name);
    }

    @Override
    public void addPurchaseInfo(PurchaseInfo purchaseInfo) {
        purchaseInfoMapper.insertSelective(purchaseInfo);
    }

    @Override
    public ArrayList<PurchaseInfo> queryAllNotPurchase() {
        return purchaseInfoMapper.queryAllNotPurchase();
    }

    @Override
    public int updateRepertory(Repertory repertory,String tradeName, int num, String type, String provider,String price) {
        repertory.setProvider(provider);
        repertory.setNumber(num);
        repertory.setType(type);
        repertory.setProductMaterialsName(tradeName);
        repertory.setProductMaterialsPrice(price);
        int rows =repertoryMapper.updateByPrimaryKey(repertory);
        return rows;
    }

    @Override
    public Repertory queryAllByName(String tradeName) {
        Repertory repertory = repertoryMapper.queryAllByName(tradeName);
        return repertory;
    }

    @Override
    public ArrayList<ProductInfo> queryAllNotProduct() {
        return productInfoMapper.queryAllNotProduct();
    }
    @Override
    public void addProductInfo(ProductInfo productInfo) {
        productInfoMapper.insertNameAndNumber(productInfo);
    }
}
